//获取当前时间（XXXX-XX-XX）
export function getCurDate() {
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var day = now.getDate();
    month = month < 10 ? "0" + month : month;
    day = day < 10 ? "0" + day : day;
    return year + "-" + month + "-" + day;
}
//向sessionStorage中存储一个JSON对象
export function setSessionStorage(keyStr, value) {
    sessionStorage.setItem(keyStr, JSON.stringify(value));
}
//从sessionStorage中获取一个JSON对象（取不到时返回null）
export function getSessionStorage(keyStr) {
    var str = sessionStorage.getItem(keyStr);
    if (str === '' || str === null || str === 'null' || str === undefined) {
        return null;
    } else {
        return JSON.parse(str);
    }
}
//从sessionStorage中移除一个JSON对象
export function removeSessionStorage(keyStr) {
    sessionStorage.removeItem(keyStr);
}
//向localStorage中存储一个JSON对象
export function setLocalStorage(keyStr, value) {
    localStorage.setItem(keyStr, JSON.stringify(value));
}
//从localStorage中获取一个JSON对象（取不到时返回null）
export function getLocalStorage(keyStr) {
    var str = localStorage.getItem(keyStr);
    if (str === '' || str === null || str === 'null' || str === undefined) {
        return null;
    } else {
        return JSON.parse(str);
    }
}
//从localStorage中移除一个JSON对象
export function removeLocalStorage(keyStr) {
    localStorage.removeItem(keyStr);
}

//自动获取位置
export default function loadBMap(ak) {
    return new Promise(function(resolve, reject) {
        if (typeof window.BMap !== 'undefined') {
            resolve(window.BMap)
            return true
        }
        window.onBMapCallback = function() {
            resolve(window.BMap)
        }
        const script = document.createElement('script')
        script.type = 'text/javascript'
        script.src =
            'https://api.map.baidu.com/api?v=3.0&ak=' + ak + '&callback=onBMapCallback' //ak表示自己的申请的ak
        script.onerror = reject
        document.head.appendChild(script)
    })
}


